When we make our programs, we need some way to tell the chip what to use for it's clock source, and various other bits of configuration information. These are actually controlled by some values saved in the chip as part of the programming process, and so we need some way to tell the programmer what values to use for the configuration.
This is done using '#pragma
' statements. These are read by the compiler and them used by mLoader when it is programming the chip to tell it how to configure itself, including how it generates the timing signals for the chip, if the Watchdog timer is enabled, and how other bits of circuitry are configured. These are things that affect the chip as soon as it's powered up, and can't be altered by the program, although in some cases the program can override options once it's running.
In this course, we've used two different configurations. The first, shown on the right, tells the device to use an RC oscillator, this is very inaccurate and slow, but required very little external hardware. It is used in the first few exercises of this course when you want the chip to run quite slowly, and also for it to be possible to alter the speed of the chip by altering the value of the resistor used .
For most of the course, we've used the second configuration used. This tells the chip to use a 'High Speed' oscillator, in this case a crystal attached to the device. This is much faster and more accurate than using an RC oscillator, but it's impossible to change the speed of the device externally.
If you look at the two parts of the configuration, the first tells the compiler what frequency the chip will be running at. This means that if you use any of the delay functions included with the compiler, it can work out how many instructions it has to run for a given time.
The second part is the actual content of the configuration value in the chip. It's composed of several values combined together using the '&' symbol, note that this isn't the same thing as when we use the '&' symbol in our C programs. The values that can be used here are detailed in the mLoader documentation that is installed with the program.
Configuration 1:
/* Set 8 MHz clock frequency */
#pragma CLOCK_FREQ 8000000
/* Set PIC16 configuration word */
#pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF
Configuration 2:
/* Set 19.6 MHz clock frequency */
#pragma CLOCK_FREQ 19660800
/* Set PIC16 configuration word */
#pragma DATA _CONFIG1, _HS_OSC & _WDT_OFF & _LVP_OFF